package at.dl.android.dota.adviser;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import at.dl.android.dota.adviser.R;

public class MyItemEntryAdapter extends CursorAdapter {

    private final LayoutInflater mInflater;

    public MyItemEntryAdapter ( Context context, Cursor cursor ) {
        super(context,cursor,false);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView ( View view, Context context, Cursor cursor ) {
        int imgId = cursor.getInt(cursor.getColumnIndex(ColumnNames.Items.item_image_id));
        String name = cursor.getString(cursor.getColumnIndex(ColumnNames.Alias._id));
        int totalCosts = cursor.getInt(cursor.getColumnIndex(ColumnNames.Items.total_costs));
        ImageView img = (ImageView) view.findViewById(R.id.img);
        img.setImageResource(imgId);
        TextView t = (TextView) view.findViewById(R.id.name);
        t.setText(name);
        t = (TextView) view.findViewById(R.id.totalCosts);
        t.setText(Integer.toString(totalCosts));
    }

    @Override
    public View newView ( Context context, Cursor cursor, ViewGroup parent ) {
        final View view = mInflater.inflate(R.layout.list_items_entry,parent,false);
        return view;
    }

}
